package com.AI;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.Display;
import android.view.View;
import android.widget.TextView;

public class CameraOverlayLayout extends View {
	public static boolean tracking = false;
	
	Paint paint;
	Display display;
	TextView tv;
	
	public CameraOverlayLayout(Context context) {
		super(context);
		init();
	}
	
	public CameraOverlayLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public CameraOverlayLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}
	
	void init()
	{
		paint = new Paint();
		paint.setColor(Color.BLUE);
		paint.setAlpha(150);
		paint.setTextSize(16);
		paint.setStyle(Style.FILL_AND_STROKE);
	}
	
	public  void toggleTracking()
	{
		if (tracking)
		{
			tracking = false;
			UserModel.Xcoord = 400;
			UserModel.Ycoord = 240;
			paint.setColor(Color.BLUE);
		}
		else{
			tracking = true;
			UserModel.ref_x_direction = UserModel.x_direction;
			UserModel.ref_y_direction = UserModel.y_direction;
			UserModel.ref_z_direction = UserModel.z_direction;
			if (Math.abs(UserModel.z_direction) > 45){
				// landscape
				UserModel.screenWidth = 45.1;
				UserModel.screenHeight = 31;
			}
			else {
				// portrait
				UserModel.screenWidth = 31;
				UserModel.screenHeight = 45.1;
			}
			paint.setColor(Color.RED);
		}
	}
	
    @Override
    protected void onDraw(Canvas canvas) {
    	
    	// Aim for 40 fps
    	canvas.drawCircle((int)UserModel.Xcoord, (int) UserModel.Ycoord, 15, paint);
    	
    	this.postInvalidateDelayed(25);
		super.onDraw(canvas);
    }
}
